import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:miaowu/app/module/mine/audio_card/container_tab_indicator.dart';
import 'package:miaowu/app/module/mine/money/integral/integral_histor_page.dart';

import 'audio/pond_publish_audio_page.dart';
import 'image/pond_publish_image_page.dart';

class PondPublishMianWidget extends StatefulWidget {
  const PondPublishMianWidget({super.key});

  @override
  State<PondPublishMianWidget> createState() => _PondPublishMianWidgetState();
}

class _PondPublishMianWidgetState extends State<PondPublishMianWidget> with TickerProviderStateMixin {
  late TabController _tabController;
  final List<Widget> _pages = [];

  late String category;

  final List<String> _tabs = ['喵图文', '喵语音', '喵个情'];

  @override
  void initState() {
    super.initState();
    _pages.add(const PondPublishImagePage(key: PageStorageKey('喵图文')));
    _pages.add(PondPublishAudioPage(key: const PageStorageKey('喵语音'), onCallBack: () {}));
    _pages.add(const IntegralHistoryPage(inorout: '1', key: PageStorageKey('收入')));
    _tabController = TabController(length: _pages.length, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: AppScreen.height * 0.7,
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(topLeft: Radius.circular(16.r), topRight: Radius.circular(16.r))),
      child: Stack(
        children: [
          Image.asset('assets/app/images/member/member_pay_bg.png'),
          Container(
            color: Colors.transparent,
            child: Column(
              children: [
                Container(
                  padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
                  child: Row(
                    children: [
                      GestureDetector(
                          onTap: () => Navigator.pop(context),
                          child: Container(
                              padding: const EdgeInsets.symmetric(horizontal: 10),
                              margin: const EdgeInsets.only(right: 20),
                              child: Image.asset('assets/app/images/member/member_pay_close.png', width: 15.sp))),
                      Expanded(child: _tabbarWarpper()),
                      const SizedBox(width: 40)
                    ],
                  ),
                ),
                Expanded(
                    child: TabBarView(
                        controller: _tabController,
                        children: _pages.map((e) {
                          return e;
                        }).toList())),
                // Container(
                //   height: 51,
                //   margin: const EdgeInsets.only(left: 20, right: 20, top: 20),
                //   alignment: Alignment.center,
                //   decoration: BoxDecoration(color: const Color(0xFF25D4D0), borderRadius: BorderRadius.circular(25)),
                //   child: Text('确认并支付',
                //       style: TextStyle(color: Colors.white, fontSize: 16.sp, fontWeight: FontWeight.w600)),
                // ),
                // SizedBox(height: AppScreen.safeAreaPaddingBottom)
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _tabbarWarpper() {
    return DefaultTabController(
      length: _pages.length,
      child: Container(
        height: 40,
        width: double.infinity,
        color: Colors.transparent,
        child: TabBar(
          // tabAlignment: TabAlignment.start,
          controller: _tabController,
          labelColor: Colors.black,
          indicatorColor: Colors.black,
          unselectedLabelColor: Colors.black.withOpacity(0.56),
          // isScrollable: true,
          indicatorWeight: 0,
          // indicator: const UnderlineTabIndicator(
          //   borderSide: BorderSide(color: Colors.black, width: 5.0),
          //   insets: EdgeInsets.symmetric(horizontal: 10.0), // 设置指示器的水平间距
          // ),
          overlayColor: WidgetStateProperty.resolveWith((states) {
            return Colors.transparent;
          }),
          dividerHeight: 0,
          indicator: ContainerTabIndicator(
              color: const Color(0xFF22F2EB),
              width: 30.w,
              height: 3.w,
              radius: const BorderRadius.all(Radius.circular(14.0)),
              padding: const EdgeInsets.only(left: 0.0, right: 0, top: 15, bottom: 0)),
          labelStyle: const TextStyle(color: Color(0xFF000000), fontSize: 15, fontWeight: FontWeight.w500),
          unselectedLabelStyle: const TextStyle(color: Color(0xFF999999), fontSize: 15, fontWeight: FontWeight.w500),
          onTap: (index) {
            logs(index);
          },
          tabs: List.generate(_tabs.length, (index) {
            // return Tab(text: _tabs[index]);
            return Tab(child: Text(_tabs[index]));
          }),
        ),
      ),
    );
  }
}
